const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const webpack = require('webpack')

module.exports = {
    entry: './src/main.js',
    output: {
        filename: 'build.js',
        path: path.resolve(__dirname, './dist'),
        publicPath: "/dist/"
    },
    module: {
        rules: [
            //vue
            {
                test: /\.vue$/,
                loader: "vue-loader"
            },
            //js
            {
                test: /\.js$/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ["@babel/preset-env"]
                    }
                }
            },
            // css
            {
                test: /\.css/,
                use: ['vue-style-loader', 'css-loader']
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new webpack.HotModuleReplacementPlugin()
    ],
    resolve: {
        alias: {
            'vue$': "vue/dist/vue.esm.js"
        },
        extensions: ['.vue', '.js', '.css', '.scss']
    },
    devServer: {
        port: 3500,
        host: "localhost",
        open: true,
        hot: true,
        before(app) {
            app.get("/api/list", (req, res, next) => {
                let list = require('./mock/list.json');
                res.json({
                    code: 1,
                    data: list
                })
            })
        }
    }
}